<template>
	<view>
		<navbar title="充值" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__box">
					<view class="con__box__title">
						充值金额
					</view>
					<view class="con__box__i">
						<view class="con__box__i__u">
							￥
						</view>
						<input type="number" class="con__box__i__inp" v-model="val" />
						元
					</view>
					<view class="con__box__title">
						选择支付方式
					</view>
					<view class="">
						<view class="con__box__pay" v-for="(item,index) in paylist" :key="index" @click="cur=index">
							<image :src="'/static/my/'+item.icon+'.png'" class="con__box__pay__icon" mode=""></image>
							<view class="" style="flex: 1;">
								<view class="con__box__pay__name">
									{{item.name}}
								</view>
								<view class="con__box__pay__text">
									{{item.text}}
								</view>
							</view>
							<view class="con__box__pay__checkbox">
								<image src="/static/my/check.png" v-if="cur==index"
									class="con__box__pay__checkbox__icon" mode=""></image>
								<image src="/static/my/nocheck.png" v-else class="con__box__pay__checkbox__icon"
									mode=""></image>
							</view>
						</view>
					</view>
					<view class="footer" @click="submit">
						<image src="/static/my/btn.png" class="btn" mode=""></image>
						<view class="footer__text">
							确认充值
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				val: '',
				paylist: [{
						name: '支付宝',
						icon: 'zfb',
						text: '推荐有支付宝账户的用户使用'
					},
					{
						name: '微信支付',
						icon: 'wx',
						text: '推荐安装微信5.0及以上版本的用户使用'
					},
				],
				cur: 0
			};
		},
		methods: {
			submit() {
				let _this=this
				if (!this.val) {
					uni.$u.toast('请输入充值金额')
					return
				}
				if (this.cur == 0) {
					user.chargeMoney({
						price: this.val
					}).then(res => {
						if (res.data.code == 1) {
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.data, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
								success: function(res1) {
									uni.$u.toast('充值成功')
									_this.val=''
									setTimeout(()=>{
										uni.redirectTo({
											url:'/pages/personal/wallet'
										})
									},1000)
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
								}
							});
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f3f7;
	}

	.con {
		padding: 20rpx 30rpx;

		&__box {
			background: #FFFFFF;
			border-radius: 26rpx;
			padding: 46rpx 30rpx 75rpx;

			&__title {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #010101;
				line-height: 30rpx;
			}

			&__i {
				padding: 37rpx 0;
				border-bottom: 3rpx solid #FAF9F9;
				display: flex;
				align-items: center;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #3A4E6D;
				line-height: 30rpx;
				margin-bottom: 39rpx;

				&__u {
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 36rpx;
					color: #3E5170;
					line-height: 26rpx;
				}

				&__inp {
					font-family: DIN Next LT Pro;
					font-weight: 500;
					font-size: 60rpx;
					color: #3A4E6D;
					min-height: 54rpx !important;
					line-height: 54rpx !important;
					flex: 1;
				}


			}

			&__pay {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 33rpx 0;
				border-bottom: 1rpx solid #F3F4F6;

				&__icon {
					width: 84rpx;
					height: 84rpx;
					margin-right: 22rpx;
				}

				&__name {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 28rpx;
					color: #040404;
					line-height: 28rpx;
				}

				&__text {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #6D6D6D;
					line-height: 24rpx;
					margin-top: 14rpx;
				}

				&__checkbox {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 35rpx;
					height: 35rpx;

					&__icon {
						width: 35rpx;
						height: 35rpx;
					}
				}
			}
		}
	}

	.footer {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 60rpx;
		position: relative;

		.btn {
			width: 617rpx;
			height: 105rpx;
		}

		&__text {
			width: 617rpx;
			display: flex;
			justify-content: center;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #3A4E6D;
			line-height: 32rpx;
			// padding-top: 33rpx;
			position: absolute;
			padding-top: 33rpx;
			top: 0;
			left: 0;
		}
	}
</style>